package com.swift.maintenance.activity;

import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.swift.base.ActivityBase;
import com.swift.base.ApplicationBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;

public class StartActivity extends ActivityBase {
	private WebView mWebview;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_start);

		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// x.view().inject(this);

		mWebview = (WebView) findViewById(R.id.wv_webview);
		mWebview.addJavascriptInterface(new JavaScriptObject(), "blin");
		mWebview.clearCache(true);
		mWebview.clearHistory();
		WebSettings mWebSettings = mWebview.getSettings();
		mWebSettings.setUseWideViewPort(true);
		mWebSettings.setLoadWithOverviewMode(true);
		mWebSettings.setJavaScriptEnabled(true);
		mWebSettings.setDomStorageEnabled(true);
		mWebSettings.setDatabaseEnabled(true);
		mWebSettings.setAppCacheEnabled(true);
		mWebSettings.setAllowFileAccess(true);
		mWebSettings.setDefaultTextEncodingName("utf-8");
		mWebview.loadUrl(AppConfig.TEXT_HOST + "/Wap/Index/app_index");

		/*if (UserInfoUtil.isLogin()) {
			// 初始化环信群组和好友的回话
			EMClient.getInstance().groupManager().loadAllGroups();
			EMClient.getInstance().chatManager().loadAllConversations();
		}*/

//		startActivity(new Intent(StartActivity.this, LoginActivity.class));
//
//		finish();
	};

	@SuppressWarnings("unused")
	private boolean isFristRun() {
		boolean isFirstRun = ApplicationBase.LocalData.getBoolean("isFirstRun",
				true);
		Editor editor = ApplicationBase.LocalData.edit();
		if (!isFirstRun) {
			return false;
		} else {
			editor.putBoolean("isFirstRun", false);
			editor.commit();
			return true;
		}
	}

	public class JavaScriptObject {
		@JavascriptInterface
		public void startlogin(String name) {
			startActivity(new Intent(StartActivity.this, LoginActivity.class));
			finish();
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mWebview != null) {
			mWebview.destroy();
		}

	}

}
